package com.lib.utils;

import android.app.Activity;

import com.lib.common.R;

/**
 * 描述：Activity 切换的动画集合 用于startActivity()和finish()方法之后
 *
 * @author FengLing
 * <p>
 * Created onChanged 2018-02-02 19:43
 * <p>
 * 定义了各种Activity的载入动画的枚举类型
 * <p>
 * <br/> 无动画 NO_ANIMATION
 * <br/> 顶部推入 TOP_PUSH_IN
 * <br/> 顶部覆盖推入 TOP_PUSH_IN_OVERLAP
 * <br/> 顶部推出 TOP_PUSH_OUT
 * <br/> 底部推入 BOTTOM_PUSH_IN
 * <br/> 底部覆盖推入 BOTTOM_PUSH_IN_OVERLAP
 * <br/> 底部推出 BOTTOM_PUSH_OUT
 * <br/> 左侧推入 LEFT_PUSH_IN
 * <br/> 左侧覆盖推入 LEFT_PUSH_IN_OVERLAP
 * <br/> 左侧推出 LEFT_PUSH_OUT
 * <br/> 右侧推入 RIGHT_PUSH_IN
 * <br/> 右侧覆盖推入 RIGHT_PUSH_IN_OVERLAP
 * <br/> 右侧推出 RIGHT_PUSH_OUT
 * <br/> 中间推入 CENTER_IN
 * <br/> 中间推出 CENTER_OUT
 * <br/> 淡入 FADE_IN
 * <br/> 淡出 FADE_OUT
 */
public final class ActivityToggleAnimUtils {

    /**
     * 顶部推入
     */
    public static final int TOP_PUSH_IN = 0x0;
    /**
     * 顶部覆盖推入
     */
    public static final int TOP_PUSH_IN_OVERLAP = 0x1;
    /**
     * 顶部推出
     */
    public static final int TOP_PUSH_OUT = 0x2;
    /**
     * 底部推入
     */
    public static final int BOTTOM_PUSH_IN = 0x3;
    /**
     * 底部覆盖推入
     */
    public static final int BOTTOM_PUSH_IN_OVERLAP = 0x4;
    /**
     * 底部推出
     */
    public static final int BOTTOM_PUSH_OUT = 0x5;
    /**
     * 左侧推入
     */
    public static final int LEFT_PUSH_IN = 0x6;
    /**
     * 左侧覆盖推入
     */
    public static final int LEFT_PUSH_IN_OVERLAP = 0x7;
    /**
     * 左侧推出
     */
    public static final int LEFT_PUSH_OUT = 0x8;
    /**
     * 右侧推入
     */
    public static final int RIGHT_PUSH_IN = 0x9;
    /**
     * 右侧覆盖推入
     */
    public static final int RIGHT_PUSH_IN_OVERLAP = 0x10;
    /**
     * 右侧推出
     */
    public static final int RIGHT_PUSH_OUT = 0x11;
    /**
     * 中间推入
     */
    public static final int CENTER_IN = 0x12;
    /**
     * 中间推出
     */
    public static final int CENTER_OUT = 0x13;
    /**
     * 淡入
     */
    public static final int FADE_IN = 0x14;
    /**
     * 淡出
     */
    public static final int FADE_OUT = 0x15;

    private ActivityToggleAnimUtils() {
        throw new NullPointerException("来个空指针~");
    }

    /**
     * @param activity  上下文
     * @param animStyle 样式
     *                  动画样式
     */
    public static void start(Activity activity, int animStyle) {
        // 载入动画
        int enterAnim;
        // 载出动画
        int exitAnim;

        switch (animStyle) {
            case TOP_PUSH_IN:

                enterAnim = R.anim.top_push_in;
                exitAnim = R.anim.bottom_push_out;
                break;
            case TOP_PUSH_IN_OVERLAP:

                enterAnim = R.anim.top_push_in;
                exitAnim = R.anim.no_animation;
                break;
            case TOP_PUSH_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.top_push_out;
                break;
            case BOTTOM_PUSH_IN:

                enterAnim = R.anim.bottom_push_in;
                exitAnim = R.anim.top_push_out;
                break;
            case BOTTOM_PUSH_IN_OVERLAP:

                enterAnim = R.anim.bottom_push_in;
                exitAnim = R.anim.no_animation;
                break;
            case BOTTOM_PUSH_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.bottom_push_out;
                break;
            case LEFT_PUSH_IN:

                enterAnim = R.anim.left_push_in;
                exitAnim = R.anim.right_push_out;
                break;
            case LEFT_PUSH_IN_OVERLAP:

                enterAnim = R.anim.left_push_in;
                exitAnim = R.anim.no_animation;
                break;
            case LEFT_PUSH_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.left_push_out;
                break;
            case RIGHT_PUSH_IN:

                enterAnim = R.anim.right_push_in;
                exitAnim = R.anim.left_push_out;
                break;
            case RIGHT_PUSH_IN_OVERLAP:

                enterAnim = R.anim.right_push_in;
                exitAnim = R.anim.no_animation;
                break;
            case RIGHT_PUSH_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.right_push_out;
                break;
            case CENTER_IN:

                enterAnim = R.anim.center_push_in;
                exitAnim = R.anim.no_animation;
                break;
            case CENTER_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.center_push_out;
                break;
            case FADE_IN:

                enterAnim = R.anim.fade_in;
                exitAnim = R.anim.no_animation;
                break;
            case FADE_OUT:

                enterAnim = R.anim.no_animation;
                exitAnim = R.anim.fade_out;
                break;
            default:
                return;
        }
        activity.overridePendingTransition(enterAnim, exitAnim);
    }
}